package server.test

import org.scalatest._
import server.world._
import server.world.action._
import server.world.item._
import server.world.character._
import server.world.map._



class BasicActionSuite extends Suite with OneInstancePerTest{

  TurnProcessor.flush()
  
def passTurns(x:Int){
  for(i <-0 to x){
    TurnProcessor.processTurn
  }
}

val testloc = CTE.makeTestMap(5, 5)


val npc1 = new NPC(testloc.tileList(0)) 


  def testMove(){
  val targettile = testloc.tileList(1)
  val move = new Move(npc1,targettile)
  TurnProcessor.addAction(move)
  passTurns(10)
  assert(npc1.tile == targettile, "Ycord: " + npc1.tile.yCor.toString())
  }
  
  def testMoveUnitCollision(){
    val npc2 = new NPC(testloc.tileList(1))
    val targettile = testloc.tileList(1)
    val move = new Move(npc1,targettile)
    assert(!move.predicate() & !targettile.isEmpty())
  }
  
  def testMoveTerrainCollision(){
    testloc.tileList(1).texure.attribute = "Wall"
    val targettile = testloc.tileList(1)
    val move = new Move(npc1,targettile)
    assert(!move.predicate & !targettile.texure.ispassable)
  }
  
  def testAttack(){
    val npc2 = new NPC(testloc.tileList(1))
    npc1.spawn
    npc2.spawn
    val starthp = npc2.hp
    val attack = new Attack (npc1,npc2)
    
    TurnProcessor.addAction(attack)
    TurnProcessor.processTurn
    
    assert(npc2.hp<starthp)
  }
  
    def testRangedAttack(){
    val npc2 = new NPC(testloc.tileList(2))
    npc1.spawn
    npc2.spawn
    val starthp = npc2.hp
    
    val bow = new RangedWeapon
    val quiver = new Quiver
    npc1.inv = Inventory(Hand1 = Some(bow), Quiver = Some(quiver))
    
    val attack = new Fire (npc1,npc2)
    TurnProcessor.addAction(attack)
    passTurns(10)
    
    assert(npc2.hp<starthp)
  }
  
    def testRemoveItem(){
      
       val bow = new RangedWeapon
       npc1.inv = Inventory(Hand1 = Some(bow))
       assert(!npc1.inv.Hand1.isEmpty)
       
       val remItem = new EmptySlot(npc1,npc1.inv.Hand1)
       TurnProcessor.addAction(remItem)
       TurnProcessor.processTurn
       
       assert(npc1.inv.Hand1.isEmpty)
    }
    
    def testEquipItem(){

      val bow = new RangedWeapon
      npc1.backpack = bow :: npc1.backpack
      
      val equipitem = new EquipItem(npc1,bow)
      TurnProcessor.addAction(equipitem)
      passTurns(5)
      
      assert(npc1.inv.Hand1 == Some(bow))
    }
  
}
